<?php

namespace app\controllers\h5\uni;

use app\controllers\h5\base\H5Controller;
use app\models\product\Product;
use app\models\product\ProductArea as Model;
use app\models\product\ProductAreaList;

class JoinController extends H5Controller
{
    public function actionTitle()
    {
        return $this->successEncode([
            't1' => '我要回盟',
            't2' => '与趋势同行 与强者共赢',
            't3' => '魅千颜邀您一起共赢鲜活细胞蓝海市场',
        ]);
    }

    public function actionProduct()
    {
        $product_ids = ProductAreaList::find()
            ->where(['area_id' => Product::$areaMap['REPORT']])
            ->select(['product_id'])
            ->column();

        $query = Product::find()
            ->where(['status' => Model::$statusMapping['OK']])
            ->andWhere(['id' => $product_ids]);


        $list = $query->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])
            ->with(['mainImage', 'scoreCost'])
            ->asArray()
            ->all();

        return $this->successEncode(['list' => $list]);
    }
}